{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;height: 750px">


    <div class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">消息标题</label>
            <div class="layui-input-block">
                <input type="text" id="title" value="{$info.title|default=''}" name="title" autocomplete="off" placeholder="请输入消息标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">消息内容</label>
            <div class="layui-input-inline" style="width: 100%;height: 300px">
                <input type="hidden" name="id" value="{$info.id|default=''}">
                <textarea id="demo" name="content" lay-verify="content">{$info.content|default=''}</textarea>            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 3rem">
            <label class="layui-form-label">通知时间</label>
            <div class="layui-input-inline">
                <input type="text" id="note_time" value="{$info.note_time|default=''}" name="note_time" autocomplete="off" placeholder="选择通知时间" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">消息类型</label>
            <div class="layui-input-inline">
                <select name="type" lay-verify="required">
                    <option value="1" {if isset($info)}{if $info.type == 1}selected{/if}{/if}>客服消息</option>
                    <option value="2" {if isset($info)}{if $info.type == 2}selected{/if}{/if}>系统消息</option>
                    <option value="3" {if isset($info)}{if $info.type == 3}selected{/if}{/if}>订单消息</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发送用户</label>
            <div class="layui-input-inline">
                <select name="user_id" lay-verify="required">
                    {foreach $user as $u}
                    <option value="{$u.id}" {if isset($info)}{if $info.user_id == $u.id}selected{/if}{/if}>{$u.user_name}</option>
                    <!--<option value="2" {if isset($info)}{if $info.type == 2}selected{/if}{/if}>系统消息</option>-->
                    <!--<option value="3" {if isset($info)}{if $info.type == 3}selected{/if}{/if}>订单消息</option>-->
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 5rem">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </div>
    </div>


</div>
{include file='common/footer'}

<script>
    // layui.use('layedit', function(){
    //     var layedit = layui.layedit;
    //     layedit.build('demo', {
    //         tool: [
    //             'strong' //加粗
    //             ,'italic' //斜体
    //             ,'underline' //下划线
    //             ,'del' //删除线
    //
    //             ,'|' //分割线
    //
    //             ,'left' //左对齐
    //             ,'center' //居中对齐
    //             ,'right' //右对齐
    //         ],
    //     });
    //     form.verify({
    //         content: function(value){
    //             layedit.sync(index);
    //         }
    //     });
    // });
</script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //
        // //日期
        // laydate.render({
        //     elem: '#date'
        // });
        // laydate.render({
        //     elem: '#date1'
        // });
        //
        // //创建一个编辑器
        var editIndex = layedit.build('demo', {
                tool: [
                    'strong' //加粗
                    ,'italic' //斜体
                    ,'underline' //下划线
                    ,'del' //删除线

                    ,'|' //分割线

                    ,'left' //左对齐
                    ,'center' //居中对齐
                    ,'right' //右对齐
                ],
            });
        //
        //自定义验证规则
        form.verify({
            pass: []
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        // //监听指定开关
        // form.on('switch(switchTest)', function(data){
        //     layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        // });



        //监听提交
        var url='{:url("admin/News/massageModify")}';
        form.on('submit(demo1)', function(data){
            data.field.title_img = $('.title_img').attr('src');
            data.field.content_img = $('.content_img').attr('src');
            // alert(data.field.content);
            $.post(url,data.field,function (obj) {
                if(obj.code==200){
                    parent.layer.msg(obj.msg, {icon: 6,time: 1000});
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index,data.field); //再执行关闭
                }
                if(obj.code==400){
                    parent.layer.msg(obj.msg, {icon: 5,time: 1000});
                }
            },"JSON");
        });


    });
</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#note_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });

    });
</script>
</body>
</html>